package wedaex.content;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class ContentExtractorSet implements XmlComponent, Serializable {
	private List<ContentExtractor> extractors = new ArrayList<ContentExtractor>();
	
	public ContentExtractorSet() {};
	
	public void addExtractor(ContentExtractor extractor) {
		removeExtractor(extractor.getName());
		extractors.add(extractor);
	}
	
	public List<ContentExtractor> getExtractors() {
		return Collections.unmodifiableList(extractors);
	}
	
	public void removeExtractor(String name) {
		for (ContentExtractor extractor : extractors) {
			if(name.equals(extractor.getName())) {
				extractors.remove(extractor);
				return;
			}
		}
	}
	
	public ContentExtractor get(String name) {
		for (ContentExtractor extractor : extractors) {
			if(name.equals(extractor.getName()))
				return extractor;
		}
		return null;
	}

	public Element toXml(Document doc) {
		// extractors tag
		Element extractorsElement = doc.createElement("extractors");
		
		for (ContentExtractor extractor : extractors) {
			extractorsElement.appendChild(extractor.toXml(doc));
		}
		return extractorsElement;
	}

}
